/*
 * InsurancePlan.java
 *
 * This program uses the if-else-if construct to calculate the
 * installment amount for an insurance plan.
 *
 
 */

package com.javacore.day3.insurance;

import java.util.Scanner;

/**
 *
 * @author
 */

public class InsurancePlan {
    
    /** Creates a new instance of InsurancePlan */
    public InsurancePlan() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // Declare and initialize the variables
        double installment = 0;
        int amount, choice = 0, years;
        Scanner input = new Scanner(System.in);
        
        // Accepting the data for the insurance plan
        System.out.println("Enter the amount you want to insure for: $");
        amount = input.nextInt();
        System.out.println("Enter the number of years you want to insure for:");
        years = input.nextInt();
        System.out.println("The following plans are available. Enter your choice:\n" +
                " 1. Monthly \n 2. Half-Yearly \n 3. Yearly");
        choice = input.nextInt();
        
        // Calculate the premium depending on the choice of the user
        if(choice == 1) {
            installment = (amount / (years - 2)) / 12;
        } else if(choice == 2) {
            installment = (amount / (years - 2)) / 2;
        } else if(choice == 3) {
            installment = (amount / (years - 2));
        } else {
            System.out.println("Invalid Choice. The valid choices are 1, 2 or 3.");
            System.exit(0);
        }
        
        // Displaying the policy details
        System.out.println("\nPolicy Details:");
        System.out.printf("Insurance Amount: \t\t $%d \n", amount);
        System.out.printf("Insurance duration (years): \t %d  \n", years);
        if(choice == 1) {
            System.out.println("Insurance Plan: \t\t Monthly \n");
        } else if(choice == 2) {
            System.out.println("Insurance Plan: \t\t Half-Yearly \n");
        } else if(choice == 3) {
            System.out.println("Insurance Plan: \t\t Yearly \n");
        }
        System.out.printf("Installment : \t\t\t $%.2f \n", installment);
    }
    
}
